package routers

import (
	"myginblog/api/v1"
	"myginblog/middleware"
	"myginblog/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	r := gin.New()
	r.Use(middleware.Logger())
	r.Use(gin.Recovery())

	auth := r.Group("api/v1")
	auth.Use(middleware.JwtToken())

	//   fmt.Println("hello")
	//   {
	//      fmt.Println("wolrd")
	//   }
	// 作用比较单纯，个人理解就是隔离区域的
	{
		// 用户模块的路由接口
		auth.PUT("user/:id", v1.EditUser)
		auth.DELETE("user/:id", v1.DeleteUser)
		// 分类模块的路由接口
		auth.POST("category/add", v1.AddCategory)

		auth.PUT("category/:id", v1.EditCategory)
		auth.DELETE("category/:id", v1.DeleteCategory)
		// 文章模块的路由接口
		auth.POST("article/add", v1.AddArticle)

		auth.PUT("article/:id", v1.EditArticle)
		auth.DELETE("article/:id", v1.DeleteArticle)

		//上传文件
		auth.POST("upload", v1.Upload)
	}

	pub := r.Group("api/v1")
	{
		pub.GET("users", v1.GetUsers)
		pub.GET("category", v1.GetCategory)
		pub.GET("article", v1.GetArticle)
		pub.GET("article/list/:id", v1.GetCateArt)
		pub.GET("article/info/:id", v1.GetArtInfo)
		pub.POST("login", v1.Login)
		pub.POST("user/add", v1.AddUser)
	}


	r.Run(utils.HttpPort)
}
